<template>
    <div class="personGateTab">
        <van-pull-refresh v-model="refreshLoading" @refresh="onRefresh">
        <div class="asynDate" v-if="asynDate && !noData">
            数据更新日期：{{ asynDate }}<br/>
            <span class="asynDateDesc">按行人入校时间排序</span>
        </div>

        <van-empty description="暂无行人进出记录" v-if="noData"/>

        <div class="content" v-if="!noData">
            <van-list
                    v-model:loading="loading"
                    :finished="finished"
                    finished-text="没有更多了"
                    :immediate-check="false"
                    @load="loadMore"
            >
            
            <ColorItem color="#FFA000"  v-for="item in taskList" :colorBorder="false"  class="carparkitem">
                <PersonGateLog :value='item' />
                </ColorItem>
            </van-list>        
            
        </div>

    </van-pull-refresh>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted, onActivated, watch } from 'vue';
import request from '@/api/request.ts'
import dialog from '@/util/DialogTool';
import ColorItem from '@/components/ColorItem.vue';
import type {  PersonInfo, PersonVisitInfo, PersonVisitQueryResult } from '@/types/common';
import PersonGateLog from '@/components/PersonGateLog.vue';

const props = defineProps({
    id:String
})

var pageNo = 1;
const asynDate = ref();
const noData = ref(false);
const carInfo = ref<PersonInfo>();
const taskList = ref<PersonVisitInfo[]>()
const loading = ref(false)
const finished = ref(false)
const refreshLoading = ref(false)


onActivated(()=>{
    window.scroll(0,0)
})

onMounted(()=>{
    init()    
});
 
const init = ()=>{
    //刷新列表
    pageNo = 1;    
    taskList.value = [];    
    getList();        
} 


watch(()=>props.id,()=>{        
    pageNo = 1;
    getList();
});

const getList = ()=>{

    dialog.showLoading();

    var staffId =  props.id;
    request.get<PersonVisitQueryResult>('/query/queryPersonGate',{pageNo,staffId})
    .then((result)=>{
        dialog.closeToast();
        loading.value = false;
        refreshLoading.value = false;

        if(result.data){
            asynDate.value = result.data.asynDate            
            carInfo.value = result.data.person;

            if(pageNo == 1) taskList.value=[]

            if(result.data.list.length > 0){                
                if(!taskList.value) taskList.value=[];

                noData.value = false;
                taskList.value = taskList.value.concat( result.data.list);
                noData.value=false;
            }else{
                //没有获取到新的内容
                if(pageNo > 1){
                    dialog.showToast('没有更多内容了');
                    noData.value = false;
                    finished.value = true;
                }
                if(pageNo ==  1){
                    noData.value=true;
                }
                
            }            
        }
    }).catch(()=>{
        loading.value = false;
        refreshLoading.value = false;
        dialog.closeToast();
    });

    
}


const loadMore = ()=>{
    if(pageNo== 1 && taskList.value?.length == 0){        
        loading.value = false;
        return;//未加载数据，不需要loadmore
    } 
    pageNo++;
    getList();    
}
 
const onRefresh = ()=>{
    pageNo = 1
    taskList.value = [];
    getList();
}

</script>


<style lang="less">
    .personGateTab{
        display: block;
        min-height: 300px;
        padding-top: 10px;

        .asynDate{
            text-align: center;
            padding:10px;
            font-size: 14px;
        }
        
        .favoPagetitle{
            font-size: 20px;
            font-weight: bold;
            padding:20px;    
            position: fixed;
            top: 0;
            width: 100%;
            z-index: 1;
            background: #fff;            
            border-bottom: 1px solid #f2f2f2;
            display: flex;
            height: 60px;
            align-items: center;
        }

      

        .carBakInfo{
            background-color: #fff;
            padding:10px;
        }
        
        .content{
            
            padding:10px;
            padding-top: 0;
            min-height: 400px;
            .loadMore{
                width: 100%;
                font-size: 12px;
                color: #4385f5;
                text-align: center;
                margin: 0.5rem auto 1rem;
            }
        }

        .carInfoContent{
            background-color: #fff;
            margin-bottom:10px;
            padding-left: 10px;
        }

        .carparkitem{
            background-color: #fff;
            margin-bottom: 6px;
        }

    }


</style>

<style lang="css">
   
 @media screen and (min-width: 1024px) {
  
    .favo  .content{
        margin-top: 15px;
        padding-left: 0;
        padding-right: 0;
    }
}
</style>